﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sebarf.Client;
using Sebarf.Core;
using Sebarf.Core.Interfaces;
using Sebarf.Services.Impl;
using Sebarf.Services.Interfaces;
using Sebarf.Utils.Interfaces;

#endregion

namespace Sebarf.Tests {
	/// <summary>
	/// Description of the class
	/// </summary>
	[TestClass]
	public class TestServiceRequest {
		#region Public Properties

		// public Properties located here

		#endregion

		#region Public Methods

		[TestMethod]
		public void RunTestOnClient() {
			var serviceLocator = new ServiceRegistrationLocatorService();
			RequestHandlerEngine server = RequestHandlerEngine.Create(serviceLocator,
																	   new IRequestHandler[] {
			                                                                                 	new ResolveServicesDependenciesRequestHandler (),
			                                                                                 	new ResolveDependenciesRequestHandler ()
			                                                                                 });
			try {
				IClient client = WcfBasedClient.Create("Client 1", server);

				// register service manuell
				serviceLocator.RegisterService(new Service1());
				serviceLocator.RegisterService(new ObjectHierarchyFlattenerService());

				Assert.IsNull(serviceLocator.GetRegisteredService<Service1>().ServiceRequest);

				// resolve service requests
				client.ProcessLocal(new ResolveServicesDependenciesRequest());

				// check if resolved
				Assert.IsNotNull(serviceLocator.GetRegisteredService<Service1>().ServiceRequest);
			}
			catch (Exception ex) {
				Assert.Fail(ex.Message);
			}
			finally {
				server.Dispose();
			}
		}

		#endregion

		#region Private Classes

		public class Service1 : Service {
			[ServiceRequest]
			public IServiceLocatorService ServiceRequest { get; set; }
		}

		#endregion
	}
}